package com.cxps.cloud.service;

import com.cxps.cloud.common.ParamExceptions;
import com.cxps.cloud.domain.User;
import com.cxps.cloud.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @ClassName UserService
 * @Description TODO
 * @Author 郝振坤
 * @Date 2022/1/6 11:49
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public void addUser(User user) {
        /*验证参数*/
        if (StringUtils.isEmpty(user.getName())){
            throw new ParamExceptions();
        }
        userMapper.insert(user);
    }

    public void updateUser(User user) {
        user.setCreateDate(new Date());
        userMapper.updateUser(user);
    }

    public List<User> queryAllDataUser(User user) {
        return userMapper.queryAllDataUser( user);
    }

    public void deleteUser(Integer id) {
        userMapper.deleteById(id);
    }
}
